from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.


# # 用户表
# class User(models.Model):
#     username = models.CharField(max_length=20)
#     password = models.IntegerField()
#     phone = models.IntegerField()
#
#     class Meta:
#         db_table = 'user'
#
#
# # 区域表
# class Area(models.Model):
#     name = models.CharField(max_length=64)
#     parent = models.ForeignKey('self', on_delete=models.SET_NULL, related_name='son', null=True)
#
#     class Meta:
#         db_table = 'tb_areas'
#
#     def __str__(self):
#         return self.name
#
#
# # 用户地址表
# class Useraddress(models.Model):
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     receive = models.CharField(max_length=50, verbose_name='接收人')
#     province = models.ForeignKey('Area', on_delete=models.CASCADE, related_name='province')
#     city = models.ForeignKey('Area', on_delete=models.CASCADE, related_name='city')
#     area = models.ForeignKey('Area', on_delete=models.CASCADE, related_name='area')
#     address = models.CharField(max_length=225)
#     mobile = models.CharField(max_length=11)
#     email = models.EmailField()
#     isdel = models.IntegerField(default=0)
#     isdelete = models.IntegerField(default=0)
#
#
# # 分类表
# class Category(models.Model):
#     name = models.CharField(max_length=10, verbose_name='名称')
#     pic = models.ImageField(null=True, blank=True)
#     parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, verbose_name='父类别')
#     level = models.IntegerField(default=1)
#     top_parent = models.IntegerField(default=0)
#
#     class Meta:
#         db_table = 'category'
#         verbose_name = '商品类别'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return self.name
#
#
# # 商品表
# class Goods(models.Model):
#     name = models.CharField(max_length=50, verbose_name='名称')
#     category1 = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='cat1_goods', verbose_name='一级类别')
#     category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='cat_goods', verbose_name='类别')
#     sales = models.IntegerField(default=0, verbose_name='销量')
#     comments = models.IntegerField(default=0, verbose_name='评价数')
#     content = models.TextField()
#     service = models.CharField(max_length=100)
#     specs = models.CharField(max_length=100, verbose_name='规格说明')
#     store = models.IntegerField(default=9999, verbose_name='库存')
#     pic = models.ImageField(null=True, blank=True)
#     users = models.ManyToManyField(User, blank=True)
#
#     class Meta:
#         db_table = 'goods'
#         verbose_name = '商品'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return self.name
#
#
# class OrderInfo(models.Model):
#     PAY_METHOD_CHOICES = (
#         (1, "货到付款"), (2, "支付宝"),
#     )
#     ORDER_STATUS_CHOICES = (
#         (1, "待支付"), (2, "待发货"), (3, "待收货"), (4, "待评价"), (5, "已完成"), (6, "已取消"),
#     )
#
#     order_no = models.CharField(max_length=64, primary_key=True, verbose_name="订单号")
#     user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="下单用户")
#     address = models.CharField(max_length=255, verbose_name="收获地址")
#     total_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="商品总金额")
#     pay_method = models.IntegerField(choices=PAY_METHOD_CHOICES, default=1, verbose_name="支付方式")
#     status = models.IntegerField(choices=ORDER_STATUS_CHOICES, default=1, verbose_name="订单状态")
#     transaction_no = models.CharField(max_length=100)
#
#     class Meta:
#         db_table = "order_info"
#         verbose_name = '订单基本信息'
#         verbose_name_plural = verbose_name
#
#
# class OrderDetail(models.Model):
#     SCORE_CHOICES = (
#         (0, '0分'), (1, '20分'), (2, '40分'), (3, '60分'), (4, '80分'), (5, '100分'),
#     )
#     order = models.ForeignKey(OrderInfo, to_field='order_no', on_delete=models.CASCADE, verbose_name="订单",
#                               related_name='details')
#     goods = models.ForeignKey(Goods, on_delete=models.CASCADE)
#     goodsname = models.CharField(max_length=100)
#     images = models.CharField(max_length=100)
#     count = models.IntegerField(default=1, verbose_name="数量")
#     price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="单价")
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#
#     class Meta:
#         db_table = "order_detail"
#         verbose_name = '订单商品'
#         verbose_name_plural = verbose_name
#
#
# # 评价表
# class Comment(models.Model):
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     goods = models.ForeignKey(Goods, on_delete=models.CASCADE)
#     content = models.TextField()
#     start = models.IntegerField(null=True)
#     show_user = models.IntegerField(default=1, null=True)
#
#     class Meta:
#         db_table = 'comment'


# 新闻表
class News(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()

    class Meta:
        db_table = 'news'
        verbose_name = '新闻'
        verbose_name_plural = verbose_name


# 广告表
class Advert(models.Model):
    title = models.CharField(max_length=100)
    pic = models.ImageField(upload_to='news', null=True)
    url = models.CharField(max_length=255)

    class Meta:
        db_table = 'advert'
        verbose_name = '广告'
        verbose_name_plural = verbose_name
